package com.hongfeng.support.util.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.io.IOUtils;

/**
 * 读取配置文件
 * 
 * @author asus
 * 
 */
public class PropertiesUtil {

	private static String PROPERTIES_FILE = "support-cfg.properties";

	public static String getConfig(String key) {
		return loadProperties().getProperty(key);
	}

	public static Properties loadProperties() {
		Properties p = new Properties();
		InputStream is = null;
		try {
			is = PropertiesUtil.class.getClassLoader().getResourceAsStream(
					PROPERTIES_FILE);
			p.load(is);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(is);
		}
		return p;
	}

	public static Properties loadProperties(String configFile) {
		Properties p = new Properties();
		InputStream is = null;
		try {
			is = new FileInputStream(configFile);
			p.load(is);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(is);
		}
		return p;
	}

}

